//
// Created by dong on 2025/10/21.
//

#ifndef BASEC_SMENU_H
#define BASEC_SMENU_H
#include "demo101.h"
#include <vector>

#include "SAction.h"


class SMenu:public Swidget
{
public:
    SMenu(Swidget* parent=nullptr);
    SMenu(const string& text,Swidget* parent=nullptr);
    SAction* addAction(const string& text);
    SAction* addAction(SAction* act);

    template <typename pr,typename ...Args>
    void connect(const string& text,pr&& f,Args&& ...args)
    {
        int pos = -1;
        for (int i=0;i<m_action.size();i++)
        {
            if (m_action[i]->text()==text)
            {
                pos = i;
                break;
            }
        }
        if (pos!=-1)
        {
            m_action[pos]->connect(f,args...);
        }
    }

protected:
    void paintEvent(SDL_Event* msg) override;
    void mousePressEvent(SDL_Event* msg) override;
    void mouseMoveEvent(SDL_Event* msg) override;
protected:
    vector<unique_ptr<SAction>> m_action;
    string m_text;
};


#endif //BASEC_SMENU_H